layui.use(['form', 'table', 'laydate', 'layarea', 'tableSelect'], function () {
    var $ = layui.jquery,

        table = layui.table,
        laydate= layui.laydate;

    //日期
    laydate.render({
        elem: '#start_time'
        ,range: true //或 range: '~' 来自定义分割字符
        ,type:'datetime'
    });


    /*列表*/
    table.render({
        elem: '#currentTableId',
        url: '/admin/ProfitData/index?action=ajax&id_arr='+$("input[name=id_arr]").val(),
        method: 'post',
        parseData: function (res) { //res 即为原始返回的数据
            console.log(res)
            $('#in_count').html(res.count.income_price);
            $('#out_count').html(res.count.pay_price);
            $('#profit_count').html(res.count.total_price);

        },
        toolbar: '#toolbarDemo',
        cols: [[
            {field: 'create_time', title: '创建日期', sort: true,},
            {field: 'pay_price', title: '支出金额', sort: true,},
            {field: 'income_price', title: '收入金额', sort: true, minWidth: 120},
            {field: 'total_price', title: '利润额',  },

            {title: '操作', toolbar: '#currentTableBar'}
        ]],
        limits: [10, 15, 20, 25, 30, 50, 100],
        limit: 10,
        page: true,
        skin: 'line,row',
        done: function (res, curr, count) {

        }
    });

    table.on('tool(currentTableFilter)',function (re) {
        if(re.event=='edit')
        {
            let index = layer.open({
                title: '支出明细',
                type: 2,
                shade: 0.2,
                maxmin: true,
                shadeClose: true,
                area: ['80%', '80%'],
                content: '/admin/ProfitData/DataDetail?create_time=' + re.data.create_time,

            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        }
        console.log(re)
    })

    // 监听搜索操作

    $("input[name='create_time']").on('blur',function (re) {
        submitInfo();
    })


    function submitInfo() {
        var param = {};
        var t = $('#formInfo [name]');


        $.each(t, function () {
            param[this.name] = this.value;
        });
        //var result = JSON.stringify(d);

        //执行搜索重载
        table.reload('currentTableId', {
            page: {
                curr: 1
            }
            , where: {
                //searchParams: result
                param
            }
        }, 'data');
        return false;
    };
});
